<?php

namespace App\Http\Controllers\Index;

use App\Models\Personal\Resume;
use Style, DB;
use App\Models\Common\WebContent;

class WebContentController extends CommonController{

    /**
     * 资讯
     * @param $type
     * @return mixed
     */
    public function WebContent($type){
        $sign = WebContent::select("title", "sign")->take(8)->get();
        $WebContent = WebContent::where('sign', $type)->first();
        $WebContent->imgPrototype = $WebContent->img;
        $WebContent->img = strstr($WebContent->img, 'http') ? $WebContent->img : asset('/upload/webcontent/' . $WebContent->img);
        $user = auth()->guard('personal')->user();
        if(!empty($user)){
            $resume = Resume::where('uid', $user->uid)->where('default', '1')->first(['id']);
            if(!empty($resume)){
                $WebContent->editorvalue = preg_replace('/<a(.*)?href=\"(.*)\/personal\/apm_activity_list\/(\d*?)\"(.*)>/Usi',
                    "<a href=\"\${2}/personal/apm_activity_list/" . $resume->id . "\"\${4}>", $WebContent->editorvalue);
            }else{
                $WebContent->editorvalue = preg_replace('/<a(.*)?href=\"(.*)\/personal\/apm_activity_list\/(\d*?)\"(.*)>/Usi',
                    "<a href=\"\${2}/personal/my_resume\"\${4}>", $WebContent->editorvalue);
            }
        }
        return Style::view("index.webContent", compact('WebContent', 'sign'));
    }

}